Skip to main content

iOS SDK

SDK quick links

In addition to this reference guide, we provide source code, API reference documentation, and sample applications at the following links:

ResourceLocation
GitHub repositoryClient Side SDK for iOS
Sample applicationsdemo-cocoapodsdemo-objcdemo-swiftpm
Published moduleCocoaPods

Swift

Step 1. Install SDK

Swift Package Manager:

1. XCode -> File -> Add Packages -> input `https://github.com/FeatureProbe/client-sdk-ios.git`
2. click `Add Package`

Cocoapods:

1. add `pod 'FeatureProbe', :git => 'git@github.com:FeatureProbe/client-sdk-ios.git'` to Podfile
2. `pod install` or `pod update`

Step 2. Create a FeatureProbe instance

import featureprobe


let url = FpUrlBuilder(remoteUrl: "https://featureprobe.io/server").build();
let user = FpUser()
user.setAttr(key: "name", value: "bob")
let config = FpConfig(
remoteUrl: url!,
clientSdkKey: "client-9d885a68ca2955dfb3a7c95435c0c4faad70b50d",
refreshInterval: 10,
waitFirstResp: true
)
let fp = FeatureProbe(config: config, user: user)

Step 3. Use the feature toggle

let showFeature = fp.boolValue("toggle_key", false)
if showFeature {
# application code to show the feature
} else {
# the code to run if the feature is off
}

Step 4. Track Events

note

The Swift SDK supports event tracking from version 2.0.2.

The event tracking feature can record the actions taken by the user in the application as events.

Events are related to toggle's metrics. For more information about event analysis, please read Event Analysis.

fp.track(event: "YOUR_CUSTOM_EVENT_NAME")
// Providing a metric value to track
fp.track(event: "YOUR_CUSTOM_EVENT_NAME", value: 5.5)

Step 5. Unit Testing (Optional)

let fp = FeatureProbe.newForTest(toggles: "{ \"toggle_1\": true }")
let is_true = fp.boolValue(key: "toggle_1", defaultValue: false)
assert(is_true == true);

Find the Demo code in example

Objective-C

Step 1. Install SDK

Cocoapods

add pod 'FeatureProbe', :git => 'git@github.com:FeatureProbe/client-sdk-ios.git' to Podfile

pod install or pod update

Step 2. Create a FeatureProbe instance

#import "FeatureProbe-Swift.h"

NSString *urlStr = @"https://featureprobe.io/server";
FpUrl *url = [[[FpUrlBuilder alloc] initWithRemoteUrl: urlStr] build];
FpUser *user = [[FpUser alloc] init];
[user setAttrWithKey:@"name" value:@"bob"];
FpConfig *config = [[FpConfig alloc] initWithRemoteUrl: url
clientSdkKey:@"client-9d885a68ca2955dfb3a7c95435c0c4faad70b50d"
refreshInterval: 10
waitFirstResp: true];
FeatureProbe *fp = [[FeatureProbe alloc] initWithConfig:config user:user];

Step 3. Use the feature toggle

bool showFeature = [fp boolValueWithKey: @"toggle_key" defaultValue: false];
if (showFeature) {
# application code to show the feature
} else {
# the code to run if the feature is off
}

Step 4. Track Events

note

The Objc SDK supports event tracking from version 2.0.2.

The event tracking feature can record the actions taken by the user in the application as events.

Events are related to toggle's metrics. For more information about event analysis, please read Event Analysis.

[fp trackWithEvent:@"YOUR_CUSTOM_EVENT_NAME"];
// Providing a metric value to track
[fp trackWithEvent:@"YOUR_CUSTOM_EVENT_NAME" value:5.5];

Step 5. Unit Testing (Optional)

#import "FeatureProbe-Swift.h"

NSString *s = @"{ \"ab_test\": \"green\"}";
FeatureProbe *fp = [[FeatureProbe alloc] initWithTestJson: s];
NSString *value = [fp stringValueWithKey:@"ab_test" defaultValue:@"red"];
NSLog(@"value is %@", value);

Find the Demo code in example